package demo4;

import java.util.*;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-11-07
 * Time: 22:29
 */
class Virus {
    private int parent;
    private int count;
    private ArrayList<Integer> children;
    private int depth;

    public Virus() {
        this.count = 0;
        this.children = new ArrayList<>();
        this.parent = -1;
        this.depth = 1;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public ArrayList<Integer> getChildren() {
        return children;
    }

    public int getParent() {
        return parent;
    }

    public void setParent(int parent) {
        this.parent = parent;
    }

    public int getDepth() {
        return depth;
    }

    public void setDepth(int depth) {
        this.depth = depth;
    }
}

public class Main {
    static ArrayList<Integer> ans = new ArrayList<>();
    private static void dfs(int index, ArrayList<Integer> arrayList,Virus[] viri) {
        if(arrayList.size() > ans.size()) {
            ans = arrayList;
        }
        for (int i = 0; i < viri[index].getCount(); i++) {
            arrayList.add(viri[index].getChildren().get(i));
            dfs(viri[index].getChildren().get(i), arrayList, viri);
            arrayList.remove(arrayList.size() - 1);
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Virus[] viri = new Virus[n];
        for (int i = 0; i < n; i++) {
            viri[i] = new Virus();
        }
        for (int i = 0; i < n; i++) {
            int count = scanner.nextInt();
            viri[i].setCount(count);
            for (int j = 0; j < count; j++) {
                int t = scanner.nextInt();
                viri[i].getChildren().add(t);
                viri[t].setParent(i);
            }
            Collections.sort(viri[i].getChildren());
        }
        for (int i = 0; i < n; i++) {
            if(viri[i].getParent() == -1) {
                ArrayList<Integer> arrayList = new ArrayList<>();
                arrayList.add(i);
                dfs(i, arrayList, viri);
                break;
            }
        }
        System.out.println(ans.size());
        for (int i = 0; i < ans.size(); i++) {
            if(i == 0) {
                System.out.print(ans.get(i));
            } else {
                System.out.println(" " + ans.get(i));
            }
        }
    }
}
